<template>
	<view class="w-100">
		<view class="mt-2 flex-1 mx-3">
			<view class="flex-1 pro-item d-f" v-for="(item,index) in collectionList" :key="index">
				<image :src="item.image_list[0].url" mode="" class="pro-img"></image>
				<view class="flex-1 ml-3 mt-2">
					<view class="font-s-4 in1line">{{ item.product_name }}</view>
					<view class="mt-1 font-s-3">¥{{ item.product_price }}</view>
					<view class="flex-1 d-f align-center font-s-3 text-muted mt-2 justify-end mr-3" @click="collectionDelete(item.id)">取消收藏</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		productcollectionListUrl,
		productcollectionDeleteUrl
	} from "@/api/index.js"
	export default {
		data() {
			return {
				queryInfo: {
					page: 1,
					page_size: 10
				},
				collectionList: []
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			init() {
				this.getProductcollectionList()
			},
			getProductcollectionList() {
				this.$R.get(productcollectionListUrl, this.queryInfo).then(res => {
					if (res.code == 200) {
						this.collectionList = res.data.list.map(item => {
							let correctedImageList = item.image_list.replace(/'/g, '"');
							item.image_list = JSON.parse(correctedImageList);
							return item;
						});
						console.log('222', this.collectionList);
					}
				});
			},
			collectionDelete(collectionId) {
				this.$R.delete(productcollectionDeleteUrl + collectionId + '/').then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '取消成功',
							icon: 'none'
						});
						this.getProductcollectionList()
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f6f6f6;
	}

	.pro-item {
		height: 180rpx;
		margin-bottom: 25rpx;
		background-color: #fff;

		.pro-img {
			width: 180rpx;
			height: 180rpx;
			margin: 5rpx;
		}
	}
</style>